﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.AccountingObject
{
    public class AccountingObjectPresenter : Presenter<IAccountingObjectView>
    {
        public AccountingObjectPresenter(IAccountingObjectView view)
            : base(view)
        {
        }

        public void Display(string accountingObjectId)
        {
            if (accountingObjectId == null) return;

            var accountingObject = Model.GetAccountingObject(accountingObjectId);

            View.AccountingObjectID = accountingObject.AccountingObjectID;
            View.AccountingObjectCode = accountingObject.AccountingObjectCode;
            View.AccountingObjectName = accountingObject.AccountingObjectName;
            View.AccountingObjectCategoryId = accountingObject.AccountingObjectCategoryId;
            View.RestaurantId = accountingObject.RestaurantId;
            View.Prefix = accountingObject.Prefix;
            View.Address = accountingObject.Address;
            View.Fax = accountingObject.Fax;
            View.Tel = accountingObject.Tel;
            View.EmailAddress = accountingObject.EmailAddress;
            View.Website = accountingObject.Website;
            View.CompanyTaxCode = accountingObject.CompanyTaxCode;
            View.BirthDate = accountingObject.BirthDate;
            View.FiredDate = accountingObject.FiredDate;
            View.Description = accountingObject.Description;
            View.ContactName = accountingObject.ContactName;
            View.JobCandidateName = accountingObject.JobCandidateName;
            View.ContactSex = accountingObject.ContactSex;
            View.ContactMobile = accountingObject.ContactMobile;
            View.ContactEmail = accountingObject.ContactEmail;
            View.ContactHomeTel = accountingObject.ContactHomeTel;
            View.ContactAddress = accountingObject.ContactAddress;
            View.IsPersonal = accountingObject.IsPersonal;
            View.IdentificationNumber = accountingObject.IdentificationNumber;
            View.IssueDate = accountingObject.IssueDate;
            View.IssueBy = accountingObject.IssueBy;
            View.IsVendor = accountingObject.IsVendor;
            View.IsCustomer = accountingObject.IsCustomer;
            View.IsEmployess = accountingObject.IsEmployess;
            View.CountryRegion = accountingObject.CountryRegion;
            View.Province = accountingObject.Province;
            View.District = accountingObject.District;
            View.Village = accountingObject.Village;
            View.IsActive = accountingObject.IsActive;
            View.DepartmentID = accountingObject.DepartmentID;
        }

        public int Save()
        {
            var accountingObject = new AccountingObjectModel
            {
                AccountingObjectID = View.AccountingObjectID,
                AccountingObjectCode = View.AccountingObjectCode,
                AccountingObjectName = View.AccountingObjectName,
                AccountingObjectCategoryId = View.AccountingObjectCategoryId,
                RestaurantId = View.RestaurantId,
                Prefix = View.Prefix,
                Address = View.Address,
                Tel = View.Tel,
                Fax = View.Fax,
                EmailAddress = View.EmailAddress,
                Website = View.Website,
                CompanyTaxCode = View.CompanyTaxCode,
                BirthDate = View.BirthDate,
                FiredDate = View.FiredDate,
                Description = View.Description,
                ContactName = View.ContactName,
                JobCandidateName = View.JobCandidateName,
                ContactSex = View.ContactSex,
                ContactMobile = View.ContactMobile,
                ContactEmail = View.ContactEmail,
                ContactHomeTel = View.ContactHomeTel,
                ContactAddress = View.ContactAddress,
                IsPersonal = View.IsPersonal,
                IdentificationNumber = View.IdentificationNumber,
                IssueDate = View.IssueDate,
                IssueBy = View.IssueBy,
                IsVendor = View.IsVendor,
                IsCustomer = View.IsCustomer,
                IsEmployess = View.IsEmployess,
                CountryRegion = View.CountryRegion,
                Province = View.Province,
                District = View.District,
                Village = View.Village,
                IsActive = View.IsActive,
                DepartmentID = View.DepartmentID
            };

            if (accountingObject.AccountingObjectID == null)
                return Model.AddAccountingObject(accountingObject);
            else
                return Model.UpdateAccountingObject(accountingObject);
        }

        public int Delete(string accountingObjectId)
        {
            return Model.DeleteAccountingObject(accountingObjectId);
        }
    }
}
